package command.project.statechart;

import javax.xml.bind.annotation.XmlTransient;

import model.Statechart;
import model.Workspace;
import model.util.Point;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import controller.ApplicationController;

public class OpenStatechartCommand extends AbstractStatechartCommand {

	private String userName;
	private Long statechartId;
	private Point position;

	@XmlTransient
	private static final Logger log = LoggerFactory
			.getLogger(OpenStatechartCommand.class);

	public OpenStatechartCommand(String userName, 
			Long StatechartId, Point position) {
		this.userName = userName;
		this.statechartId = StatechartId;
		this.position = position;
	}

	@Override
	public void executeLocal(ApplicationController applicationController) {
		log.debug("Executing command : OpenStatechartCommand ...");
		Workspace workspace = applicationController.getModel()
				.getCurrentProject().getWorkspace(userName);
		if (workspace != null) {
			Statechart statechart = applicationController.getModel()
					.getCurrentProject().getStatechartById(statechartId);
			if (statechart != null) {
				workspace.addStatechart(statechart);
				workspace.setStatechartLocation(statechart.getId(), position);
			}
		}
		log.debug("Executing command : OpenStatechartCommand DONE");
	}

	@Override
	public void executeRemote(ApplicationController applicationController) {

	}

}
